<#include "/common/seajs/layout/action_upload_head_layout.html" />
<@action_upload_head_layout>
<title>${jxrb.message(actionName,"systemDataImport.configInfo")}${(systemDataImportConfig.config_name)!}</title>
<script>
  seajs.use(["jquery","jx_upload","jx_msgbox_plus","${jxwebpath.js}seajs/staff"],function($,jxUpload,msgbox,staff){
  function DataImport()
  {
    var action = '${action}';
    if (action == 'added' || action == 'edited' || action == 'readExcelSaves') 
    {
      if (action == 'added' || action == 'edited') 
      {
        if (!checkConfig())
          return;
      }
      jxUpload.submitFile(
              function() {
                clearForm();
                if(action == 'readExcelSaves')
                  changeData();
              },
              function() {
                location.href = "${controllerKey}";
              }
      );
    }
    else
    {
      msgbox.confirm({url: "${controllerKey}${action}/"},
      function()
      {
        msgbox.close();
        if (msgbox.messageType != 2)
          location.href = "${controllerKey}";
      }, function()
      {
        if (msgbox.messageType != 2)
          location.href = "${controllerKey}";
      });
    }
  }

  function clearForm()
  {
    var action = '${action}';
    if (action == 'added')
    {
      $("#configName").val('');
      $("#tableName").val('');
      $("#templeteFile").val('');
      $("#dataCell").val('');
    }
  }
  function checkConfig()
  {
    var configName = $("#configName").val();
    var tableName = $("#tableName").val();
    var dataCell = $("#dataCell").val();
    var reg = /^[1-9]\d*$/;
    if (configName == "" | configName == null) {
      alert('${jxrb.message("systemDataImport.configName,public.isNotNull")}');
      return false;
    }
    if (tableName == "" | tableName == null) {
      alert('${jxrb.message("systemDataImport.tableName,public.isNotNull")}');
      return false;
    }
    if (dataCell == "" | dataCell == null) {
      alert('${jxrb.message("systemDataImport.dataCell,public.isNotNull")}');
      return false;
    }
    else
    {
      if (!reg.exec(dataCell))
      {
        alert('${jxrb.message("systemDataImport.dataCell,OnlyNum")}');
        return false;
      }
    }
    return true;
  }
  function checkfiles() {
    $.ajax({
      url: "../checkfile/${(systemDataImportConfig.config_id)!}",
      dataType: "text",
      success: function(data)
      {
        if (data == "0")
          alert('<@jx_msg key="public.noresource"/>');
        else
          location.href="${controllerKey}download/${(systemDataImportConfig.config_id)!}";
      }
    });
  }
 
  function pageDataImportRefresh(strUrl)
  {
    msgbox.load({url:encodeURI(strUrl),type:"GET"},function(data)
    {
      $("#dataInfo").html(data) ;
    }) ;
  }
  
  function changeData(){
    var action = '${action}';
    var configId = $("#configId").val();
    if(action == "readExcelSaves"){
      pageDataImportRefresh(encodeURI('${jxwebpath.item}dataImportConfig/indexData/'+configId)) ;
    }
  }
  window.DataImport = DataImport;
  window.checkfiles = checkfiles;
  window.deleteData = staff.deleteData;
  window.addDatas = staff.addDatas;
  window.addFields = staff.addFields;
  window.jxUpload = jxUpload ;
});
</script>
</@action_upload_head_layout>
<#include "/common/layout/action_upload_body_layout.html" />
<@action_upload_body_layout>
<#if action == 'added' || action == 'edited' >
<#include "info.html" />
</#if>
<#if action == 'readExcelSaves'>
<#include "uploadData.html" />
</#if>
<br/>
<center>
  <#if action == 'added' || action == 'edited' || action == 'readExcelSaves'>
  <input type="button" class="inputbutton" onclick="DataImport();" value='${jxrb.message("action.submit")}' />&nbsp;&nbsp;&nbsp;&nbsp;
  </#if>
  <#include "/common/return.html" />
  <@return/> 
</center>
<br />
<div id="dataInfo">
  
</div>
</@action_upload_body_layout>
